﻿using UnityEngine;
using System;
using System.Collections;
using Hont.C2UTool;


public class StaticInfoResourceLoader : MonoBehaviour, IC2UStaticInfoReceiver
{
    public string resourcePath;
    public bool isResetPSR;


    public void OnStaticInfoReplaced()
    {
        var res = Resources.Load<GameObject>(resourcePath);

        if (res == null)
            throw new System.Exception("StaticInfoResourceLoader - Resource Not Found, Path: " + resourcePath);

        var instance = MonoBehaviour.Instantiate(res) as GameObject;
        instance.name = res.name;
        instance.transform.parent = transform;

        if (isResetPSR)
        {
            instance.transform.localPosition = Vector3.zero;
            instance.transform.localEulerAngles = Vector3.zero;
            instance.transform.localScale = Vector3.one;
        }

        instance.transform.SetSiblingIndex(transform.GetSiblingIndex());
        DestroyImmediate(this);
    }

    public void OnStaticInfoWillReplace()
    {
    }
}
